<?php
error_reporting(0);
include_once("function/fileSystem.php");
include_once("function/database.php");

if (empty($_POST)) {
    exit("您提交的表单数据超过post_max_size! <br>");
}

// 判断输入密码与确认密码是否相同
$password = $_POST['password'];
$confirmPassword = $_POST['confirmPassword'];
if ($password != $confirmPassword) {
    exit("输入的密码与确认密码不相等！");
}

$userName = $_POST['userName'];
$userName = $userName ;

$remark = $_POST['remark'];

$json_string = file_get_contents('usr.json');

$d = json_decode($json_string,true);
if (in_array($userName,$d)) {
    echo "您请求的用户名已经被注册！";
    echo "<a href='login.html'>重试</a>";
} else {
    if($d['ip'][$_SERVER['REMOTE_ADDR']]>8) {
        echo "您的ip地址注册异常，请更换网络环境重试！";

        echo "<a href='login.html'>重试</a>";
    }else{
        if (in_array($d['ip'],$_SERVER['REMOTE_ADDR']))$d['ip'][$_SERVER['REMOTE_ADDR']]=$d['ip'][$_SERVER['REMOTE_ADDR']]+1;
        $d[$userName]['ip']=$_SERVER['REMOTE_ADDR'];
        $d[$userName]['pass']="$password";
        $d[$userName]['remark']="$remark";
        setcookie('usn',$userName);
        setcookie('pwd',$password);
        $json_strings = json_encode($d);
        file_put_contents("usr.json",$json_strings);
        echo '注册成功！已自动为您登陆';
    }

}